//
//  evaluateView.m
//  phmall
//
//  Created by admin on 2017/9/18.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "EvaluateView.h"
#import "EvaluateModel.h"
@interface EvaluateView (){
    CGFloat y ;
}
@property(nonatomic,strong)UILabel *title;

@property(nonatomic,strong)UIView *moreLine;
@end


@implementation EvaluateView
-(instancetype)init{
    if (self=[super init]) {
        self.backgroundColor=[UIColor whiteColor];
        self.title=[[UILabel alloc] init];
        self.title.text=@"商品评价(243)";
        [self addSubview:self.title];
        
//        NSArray *textArr=@[@"全部",@"好评(3)",@"中评(0)",@"差评(0)",@"晒图(1)"];
//
//        y = 10;
//        CGFloat letfWidth = 15;
//        for (int i = 0; i < textArr.count; i++) {
//            NSString *text = textArr[i];
//            CGFloat width = [self getWidthWithStr:text] + 10;
//            if (letfWidth + width + 15 > SCREEN_WIDTH) {
//                y += 30;
//                letfWidth = 15;
//            }
//            UILabel *label = [[UILabel alloc] init];
//            [self addSubview:label];
//
//            [label mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.height.offset(20);
//                make.left.equalTo(self).with.offset(letfWidth);
//                make.top.equalTo(self.title.mas_bottom).with.offset(y);
//                make.width.offset(width);
//
//            }];
//            label.userInteractionEnabled = YES;
//            label.font = [UIFont systemFontOfSize:12];
//            label.text = text;
//            label.backgroundColor=[UIColor redColor];
//            label.layer.cornerRadius = 5;
//            label.layer.masksToBounds=YES;
//            label.textAlignment = NSTextAlignmentCenter;
//
//            [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tagDidCLick:)]];
//            letfWidth += width + 10;
//
//        }
//
        self.line=[[UIView alloc] init];
        [self addSubview:self.line];
        self.line.backgroundColor=[UIColor groupTableViewBackgroundColor];
        
        self.head=[[UIImageView alloc]init];
        [self addSubview:self.head];
//        self.head.image=[UIImage imageNamed:@"头像"];
        self.head.layer.cornerRadius = 5;
        
        self.name=[[UILabel alloc] init];
  
        self.name.font=[UIFont systemFontOfSize:15];
        [self addSubview:self.name];
        
        self.time=[[UILabel alloc] init];
        [self addSubview:self.time];
        self.time.font=[UIFont systemFontOfSize:13];
        self.time.textColor=[UIColor colorWithHexString:@"#c5c5c5"];
       
//        self.specification=[[UILabel alloc] init];
//        [self addSubview:self.specification];
//        self.specification.font=[UIFont systemFontOfSize:13];
//        self.specification.textColor=[UIColor colorWithHexString:@"#c5c5c5"];
//        self.specification.text=@"番茄红";
        
        self.text=[[UILabel alloc] init];
        [self addSubview:self.text];
        self.text.font=[UIFont systemFontOfSize:13];
        self.text.numberOfLines=0;
     
        
        self.moreLine=[[UIView alloc] init];
        [self addSubview:self.moreLine];
        self.moreLine.backgroundColor=[UIColor groupTableViewBackgroundColor];
        
        self.enter=[UIButton buttonWithType:UIButtonTypeCustom];
        self.enter.titleLabel.font=[UIFont systemFontOfSize:15];
//        ViewBorderRadius(self.enter, 5, 1, [UIColor orangeColor]);
        [self.enter setImage:[UIImage imageNamed:@"下拉"] forState:UIControlStateNormal];
        [self.enter setTitle:@"查看全部评价" forState:UIControlStateNormal];
        [self.enter setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self addSubview:self.enter];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).with.offset(15);
    }];
    
   
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).with.offset(15);
        make.right.equalTo(self.mas_right).with.offset(-15);
        make.height.offset(1).priorityHigh();
        make.top.equalTo(self.title.mas_bottom).with.offset(10);
//        make.bottom.equalTo(self.mas_bottom);
    }];

}
-(void)setEvaluateArray:(NSMutableArray *)evaluateArray{
    _evaluateArray=evaluateArray;
    self.title.text=[NSString stringWithFormat:@"%@(%lu)",Localized(@"商品评价"),(unsigned long)evaluateArray.count];
    
    if (self.evaluateArray.count!=0) {
        EvaluateModel *model=evaluateArray[0];
        UserInfoModel *userModel=model.user_info[0];
        self.name.text=userModel.member_id;
        [self.head sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@union/%@",IMGURL,userModel.member_image]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
        self.time.text=[PublicClass timeWithTimeIntervalString:model.reg_date];
        self.text.text=model.comment;
        
        [self.head mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.line).with.offset(10);
            make.left.equalTo(self.line);
            make.width.height.offset(50);
        }];
        
        [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.head);
            make.left.equalTo(self.head.mas_right).with.offset(10);
        }];
        
        [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.head.mas_bottom).with.offset(10);
            make.left.equalTo(self).with.offset(15);
        }];
        //
        //    [self.specification mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.top.equalTo(self.head.mas_bottom).with.offset(10);
        //        make.left.equalTo(self.time.mas_right).with.offset(15);
        //    }];
        
        [self.text mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.time.mas_bottom).with.offset(10);
            make.left.equalTo(self).with.offset(15);
            make.width.offset(SCREEN_WIDTH-30);
        }];
        
        [self.moreLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(15).priorityHigh();
            make.right.equalTo(self.mas_right).with.offset(-15).priorityHigh();
            make.height.offset(1);
            make.top.equalTo(self.text.mas_bottom).with.offset(10);
            //        make.bottom.equalTo(self.mas_bottom);
        }];
        
        [self.enter mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.moreLine.mas_bottom).with.offset(10);
            make.centerX.equalTo(self).offset(0);
        }];
        [self.enter layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
    }
}
@end
